package org.fastsyncer.core.service.impl;

import org.fastsyncer.common.entity.BaseInfo;
import org.fastsyncer.connector.framework.Connector;
import org.fastsyncer.connector.framework.ConnectorFactory;
import org.fastsyncer.core.service.ConnectorService;
import org.springframework.stereotype.Service;

@Service("ConnectorService")
public final class ConnectorServiceImpl implements ConnectorService {

    private ConnectorFactory factory = ConnectorFactory.getInstance();
    
    @Override
    public BaseInfo getBaseInfoConnector(String connector, Object config) throws IllegalAccessException {
        Connector conn = factory.getConnector(connector);
        if (null == conn) {
            throw new IllegalAccessException("无法找到该连接器.");
        }
        
        BaseInfo baseInfo = conn.getBaseInfoConnector(config);
        if (null == baseInfo || null == baseInfo.getMetaInfo()) {
            throw new IllegalAccessException("无法连接,请检查参数.");
        }
        return baseInfo;
    }

}
